package com.bilibili.duotai1;
//认识多态
public class Test {
    public static void main(String[] args) {
        //对象多态、行为多态
        Animal a1 = new Wolf();
        a1.run();//方法：编译看左边(Animal)，运行看右边(Wolf)
        System.out.println(a1.name);//成员变量都看左边
        go(a1);
        Animal a2 = new Tortoise();
        a2.run();//方法：编译看左边，运行看右边
        Tortoise a2p = (Tortoise) a2 ;
        System.out.println(a2p.name);
        go(a2);
    }
    public static void go(Animal a){
        if(a instanceof Wolf){
            Wolf w1 = (Wolf)a;
            w1.eatsheep();
        }
        else if(a instanceof Tortoise){
            Tortoise t1 = (Tortoise) a;
            t1.shrikHead();
        }
    }
}
